<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="author" content="纪德朝">
    <title></title>
    <style>
        body {
            margin: 0;
        }

        .box {
            width: 1000px;
            position: relative;
            /* margin: 100px auto;      */
        }

        ul {
            width: 500px;
            margin: 20px auto;
            height: 300px;
        }

        li {
            list-style: none;
            position: absolute;
            /* top: 0px;
        left: 0px; */
        }

        .xianshi {
            z-index: 100;
        }

        section {
            display: flex;
            position: absolute;
            bottom: 100px;
            left: calc(50% - 50px);
            z-index: 110;
            border-radius: 100px;
            background-color: wheat;
        }

        section div {
            width: 10px;
            height: 10px;
            border-radius: 10px;
            background-color: white;
            margin: 10px;
        }
        .red{
            background-color: red;
        }
    </style>
</head>

<body>
    <div class="box">
        <ul>
            <li class="xianshi"><a href="#"><img src="img/01.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/02.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/03.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/04.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/05.jpg" alt=""></a></li>
        </ul>
        <section>
            <div class="red"></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </section>
        <main>
            <div class="left">＞</div>
            <div class="right">＜</div>
        </main>
    </div>
</body>
<script>
    var li = document.querySelectorAll('li');
    var div = document.querySelectorAll('section div');
    var a = 0;
    var timer = setInterval(change, 1000);
    // setInterval(change, 1000);
    function change() {
        for (var i = 0; i < li.length; i++) {

            div[i].style.backgroundColor = 'white';
            li[i].className = '';
            // console.log(i);            
        }

        a++;
        if (a == 5) {
            a = 0;
        }
        // console.log(index);        
        li[a].className = 'xianshi';
        div[a].style.backgroundColor = 'red';

    }
    var time = null;
    for (var i = 0; i < div.length; i++) {
        div[i].index = i;
        div[i].onmouseover = function (ev) {
            for (var j = 0; j < li.length; j++) {
                li[j].className = '';
                div[j].style.backgroundColor = 'white';
            }
            div[this.index].style.backgroundColor = 'red';
            li[this.index].className = 'xianshi';
            
            // if (time == null) {
            clearInterval(timer);
            // }
        }
        div[i].onmouseout = function () {
            timer = setInterval(change, 1000);
            div[this.index].style.backgroundColor = 'white';
        }
    }

</script>

</html>